//
//  HomePagePreviousViewController.m
//  product_B
//
//  Created by lanou on 16/5/30.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "HomePagePreviousViewController.h"
#import "HomePageCollectionViewController.h"

@interface HomePagePreviousViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)NSMutableArray *listArray;
@property (nonatomic,strong)UITableView *tableView;

@end

@implementation HomePagePreviousViewController

- (instancetype)init{
    if (self = [super init]) {
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake((kWidth - 50) / 2-25, 25, 100, 30)];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.listArray = [[NSMutableArray alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    self.titleLabel.text = @"往期列表";
    self.searchButton.frame = CGRectMake(20, 30, 50, 20);
    [self.searchButton setTitle:@"返回" forState:UIControlStateNormal];
    [self.searchButton setTintColor:[UIColor grayColor]];
    [self.searchButton setBackgroundImage:nil forState:UIControlStateNormal];
    
    [self.musicButton removeFromSuperview];
    [self.userButton removeFromSuperview];

    
    NSMutableArray *array = [[NSMutableArray alloc]init];
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"MM"];
    NSString *currentString = [dateFormatter stringFromDate:currentDate];
    NSInteger dateMonth = [currentString integerValue];
    for (int i = 3; i <= 6; i++) {
        if (i<6) {
            for (int j = 1; j <= 12; j++) {
            NSString *dateString = [NSString stringWithFormat:@"201%d-%.2d",i,j];
                [array addObject:dateString];
            }
        }else{
            for (int j = 1; j <= dateMonth; j++) {
                NSString *dateString = [NSString stringWithFormat:@"201%d-%.2d",i,j];
                [array addObject:dateString];
            }
        }
    }
    
    for (int i = (int)array.count-1; i>=0; i--) {
        [self.listArray addObject:array[i]];
    }

    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, kWidth, kHeight-64) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:_tableView];
 

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.listArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    NSString *dateString = self.listArray[indexPath.row];
    cell.textLabel.text = dateString;
    if (indexPath.row == 0) {
        cell.textLabel.text = @"本月";
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    HomePageCollectionViewController *homePageCollectionVC = [[HomePageCollectionViewController alloc]init];
    NSString *dateString = self.listArray[indexPath.row];
    homePageCollectionVC.dateString = dateString;
    [self.navigationController pushViewController:homePageCollectionVC animated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}
- (void)searchButtonAction:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
